<?php

namespace App\Http\Controllers\Coupon;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\Coupon;
use Illuminate\Http\Request;

class CouponController extends Controller
{
    //
    use ResponseData;
    public function list(Coupon $coupon,Request $request){
        $size = $request->input('size',10);
        $data = $coupon->query()->orderBy('id','desc')->paginate($size);
        return $this->success($data);
    }
    public function store(Coupon $coupon,Request $request){
        $data = $request->all();
        $coupon->fill($data);
        $coupon->save();
        return $this->success('保存成功');
    }
    public function edit(Coupon $coupon,Request $request){
        $data = $coupon->find($request->id);
        return $this->success($data);
    }
    public function update(Coupon $coupon,Request $request){
        $data = $coupon->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(Coupon $coupon,Request $request){
        $data = $coupon->find($request->id);
        $data->delete();
    }
}
